/* vim:ft=objc:
 * $Id: ActivityController.m 127 2005-05-17 21:56:51Z bmoore $
 *
 * Copyright (c) 2004, 2005  Branden J. Moore.
 *
 * This file is part of MacBiff, and is free software; you can redistribute
 * it and/or modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * MacBiff is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with MacBiff; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA  02111-1307 USA.
 *
 */

#import <AppKit/AppKit.h>
#import "ActivityController.h"
#import "ActivityViewController.h"
#import "ActivityCell.h"

ActivityController *activityControl = Nil;

@implementation ActivityController

- (id) init
{
	if ( (self = [super init]) != Nil ) {
		activityControl = self;
		actViewControls = [[NSMutableArray alloc] init];
		actViewNames = [[NSMutableArray alloc] init];
	}
	return self;
}

- (void) awakeFromNib
{
	[viewColumn setDataCell: [[[ActivityCell alloc] init] autorelease]];
	[viewColumn setEditable: NO];
}

- (void) dealloc
{
	if ( actViewControls ) [actViewControls release];
	if ( actViewNames ) [actViewNames release];
	[super dealloc];
}


- (IBAction)activityButtonCell:(id)sender
{
}


- (void) registerActivityViewController: (ActivityViewController*) acv
			       withName: (NSString*) name;
{
	[actViewControls addObject: acv];
	[actViewNames addObject: name];
	[self reloadTableView: Nil];
}


- (void) deregisterActivityViewController: (ActivityViewController*) acv
{
	int idx = [actViewControls indexOfObject: acv];
	if ( idx != NSNotFound ) {
		[actViewControls removeObjectAtIndex: idx];
		[actViewNames removeObjectAtIndex: idx];
		[self reloadTableView: Nil];
	}
}


- (void) reloadTableView: (id) obj
{
	while ( [[tableView subviews] count] > 0 ) {
		[[[tableView subviews] lastObject]
			removeFromSuperviewWithoutNeedingDisplay];
	}

	[tableView reloadData];
}


/* Table Delegate methods */
- (BOOL) selectionsShouldChangeInTableView: (NSTableView*) tv
{
	return NO;
}

- (void) tableView: (NSTableView*) tv didClickTableColumn: (NSTableColumn*) tc
{
	return;
}

- (void) tableView: (NSTableView*) tv didDragTableColumn: (NSTableColumn*) tc
{
	return;
}

- (void) tableView: (NSTableView*) tv mouseDownInHeaderOfTableColumn: (NSTableColumn*) tc
{
	return;
}

- (BOOL) tableView: (NSTableView*) tv shouldEditTableColumn: (NSTableColumn*) tc row: (int) row
{
	return YES;
}

- (BOOL) tableview: (NSTableView*) tv shouldSelectRow: (int) row
{
	return NO;
}

- (BOOL) tableView: (NSTableView*) tv shouldSelectTableColumn: (NSTableColumn*) tc
{
	return YES;
}

- (void) tableView: (NSTableView*) tv willDisplayCell: (id) cell forTableColumn: (NSTableColumn*) tc row: (int) row
{
	if ( [cell isKindOfClass: [ActivityCell class]] ) {
		[(ActivityCell*)cell addSubview:
			[[actViewControls objectAtIndex: row] view]];
	}
}

- (void) tableViewColumnDidMove: (NSNotification*) notification
{
	return;
}

- (void) tableViewColumnDidResize: (NSNotification*) notification
{
	return;
}

- (void) tableViewColumnDidChange: (NSNotification*) notification
{
	return;
}

- (void) tableViewColumnIsChanging: (NSNotification*) notification
{
	return;
}


/* Table DataSource Methods */
- (int) numberOfRowsInTableView: (NSTableView *)tableView
{
	return [actViewControls count];
}


- (id) tableView: (NSTableView *)tableView
	objectValueForTableColumn: (NSTableColumn *)tableColumn
	row: (int)row
{
	if ( (tableColumn == viewColumn) ) {
		return Nil;
	} else {
		return [actViewNames objectAtIndex: row];
	}
}


- (void) tableView: (NSTableView *)tableView
	setObjectValue: (id)object
	forTableColumn: (NSTableColumn *)tableColumn
	row: (int)row
{
}


@end
